package com.coderg.gmall.product.controller;

import com.coderg.gmall.common.result.Result;
import com.coderg.gmall.product.util.FileUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


/**
 * @Description
 * @Author CoderG
 * @Date 2025/5/21 2:08
 **/
@Api("文件上传到fds")
@RestController
@RequestMapping("/file")
public class FileUploadController {
    @Value("${fileServer.url}")
    private String fileUrl;

    /**
     * 文件上传
     *
     * @param file
     * @return
     */
    @PostMapping(value = "/upload")
    public Result upload(@RequestParam("file") MultipartFile file) throws Exception {

        String path = FileUtil.fileUpload(file);
        return Result.ok(fileUrl + path);
    }

}
